home *** CD-ROM | disk | FTP | other *** search
/ Scene 96 / Scene 96 International Edition (Zyklop Software) (Disc 2) (1997).iso / misc / coding / cp2dekit / samples / inppplay.cpp < prev    next >
C/C++ Source or Header  |  1996-12-29  |  6KB  |  260 lines

  1. //***************************************************************************
  2. //
  3. // this file is (c) '94-'96 Niklas Beisert
  4. //
  5. // this file is part of the cubic player development kit.
  6. // you may only use/modify/spread this file under the terms stated
  7. // in the cubic player development kit accompanying documentation.
  8. //
  9. //***************************************************************************
  10.  
  11. //[defaultconfig] ;// default configuration
  12. //  link=playinp
  13. //[fileselector] ;// default fileselector section
  14. //  readdirs=_inpReadDirReg
  15. //[filetype 23]
  16. //  color=2
  17. //  name=INP
  18. //  interface=_plCubicPlayer
  19. //  player=_inpPlayer
  20.  
  21.  
  22.  
  23.  
  24.  
  25. // player example
  26. // sampling example
  27. // additional readdir example
  28.  
  29. #include <ctype.h>
  30. #include <stdlib.h>
  31. #include <string.h>
  32. #include <conio.h>
  33. #include "pfilesel.h"
  34. #include "poutput.h"
  35. #include "sampler.h"
  36. #include "psetting.h"
  37. #include "ss.h"
  38. #include "devigen.h"
  39. #include "devisamp.h"
  40. #include "cpiface.h"
  41.  
  42. static char cdpMode;
  43.  
  44. static void cdaDrawGStrings(short (*buf)[132])
  45. {
  46.   if (plScrWidth==80)
  47.   {
  48.     writestring(buf[0], 0, 0x09, "  mode: ..........  ", 80);
  49.     writestring(buf[0], 8, 0x0F, cdpMode?"microphone":"line-in", 10);
  50.     writestring(buf[1], 0, 0, "", 80);
  51.     writestring(buf[2], 0, 0, "", 80);
  52.   }
  53.   else
  54.   {
  55.     writestring(buf[0], 0, 0x09, "    mode: ..........  ", 132);
  56.     writestring(buf[0], 10, 0x0F, cdpMode?"microphone":"line-in", 10);
  57.     writestring(buf[1], 0, 0, "", 132);
  58.     writestring(buf[2], 0, 0, "", 132);
  59.   }
  60. }
  61.  
  62.  
  63.  
  64.  
  65. static void cdaCloseFile()
  66. {
  67.   smpCloseSampler();
  68. }
  69.  
  70.  
  71.  
  72.  
  73. static int inpProcessKey(unsigned short key)
  74. {
  75.   if (smpProcessKey)
  76.   {
  77.     int ret=smpProcessKey(key);
  78.     if (ret==2)
  79.       cpiResetScreen();
  80.     if (ret)
  81.       return 1;
  82.   }
  83.   return 0;
  84. }
  85.  
  86.  
  87.  
  88.  
  89.  
  90. static int inpOpenFile(const char *path, moduleinfostruct &info, binfile *)
  91. {
  92.   char name[_MAX_FNAME];
  93.   char ext[_MAX_FNAME];
  94.  
  95.   _splitpath(path, 0, 0, name, ext);
  96.  
  97.   if (stricmp(name, "DEFAULT"))
  98.     smpSetDevice(name, 0);
  99.  
  100.   if (!smpSample)
  101.     return -1;
  102.  
  103.   cdpMode=strcmp(ext, ".MIC")?1:0;
  104.  
  105.   smpSetSource(cdpMode?SMP_LINEIN:SMP_MIC);
  106.  
  107.   plDrawGStrings=cdaDrawGStrings;
  108.   plGetMasterSample=smpGetMasterSample;
  109.   plGetRealMasterVolume=smpGetRealMasterVolume;
  110.   plProcessKey=inpProcessKey;
  111.  
  112.   smpSetOptions(plsmpRate, plsmpOpt);
  113.  
  114.   void *buf;
  115.   int len;
  116.   if (!smpOpenSampler(buf, len))
  117.     return -1;
  118.  
  119.   return 0;
  120. }
  121.  
  122. static int inpReadDir(modlist &ml, unsigned short dirref, const char *mask, unsigned long opt)
  123. {
  124.   if (!plSamplerDevices)
  125.     return 1;
  126.  
  127.   char path[_MAX_PATH];
  128.  
  129.   modlistentry m;
  130.  
  131.   if (opt&RD_PUTDSUBS)
  132.   {
  133.     fsConvFileName12(m.name, "@:", "");
  134.     m.fileref=0xFFFF;
  135.     m.dirref=dmGetDriveDir(0);
  136.     if (!mdbAppendNew(ml, m))
  137.       return 0;
  138.   }
  139.  
  140.   if (opt&RD_PUTSUBS)
  141.   {
  142.     dmGetPath(path, dirref);
  143.     if (!strcmp(path, "@:\\"))
  144.     {
  145.       fsConvFileName12(m.name, "INPUTS", "");
  146.       dmGetPath(path, dirref);
  147.       strcat(path, "INPUTS");
  148.       m.dirref=dmGetPathReference(path);
  149.       if (m.dirref==0xFFFF)
  150.         return 0;
  151.       m.fileref=0xFFFE;
  152.       if (!mdbAppend(ml, m))
  153.         return 0;
  154.     }
  155.   }
  156.  
  157.   dmGetPath(path, dirref);
  158.   if (!strcmp(path, "@:\\INPUTS\\"))
  159.   {
  160.     devinfonode *dev;
  161.     for (dev=plSamplerDevices; dev; dev=dev->next)
  162.     {
  163.       char hnd[9];
  164.       strcpy(hnd, dev->handle);
  165.       strupr(hnd);
  166.       fsConvFileName12(m.name, hnd, ".LIN");
  167.       if (fsMatchFileName12(m.name, mask))
  168.       {
  169.         m.dirref=dirref;
  170.         m.fileref=mdbGetModuleReference(m.name, dev->ihandle);
  171.         if (m.fileref==0xFFFF)
  172.           return 0;
  173.         if (mdbGetModuleType(m.fileref)!=mtINP)
  174.         {
  175.           moduleinfostruct mi;
  176.           mdbGetModuleInfo(mi, m.fileref);
  177.           mi.flags1|=MDB_VIRTUAL;
  178.           mi.channels=2;
  179.           strcpy(mi.modname, dev->dev.dev->name);
  180.           mi.modtype=mtINP;
  181.           mdbWriteModuleInfo(m.fileref, mi);
  182.         }
  183.         if (!mdbAppend(ml, m))
  184.           return 0;
  185.       }
  186.       strcpy(hnd, dev->handle);
  187.       strupr(hnd);
  188.       fsConvFileName12(m.name, hnd, ".MIC");
  189.       if (fsMatchFileName12(m.name, mask))
  190.       {
  191.         m.dirref=dirref;
  192.         m.fileref=mdbGetModuleReference(m.name, dev->ihandle);
  193.         if (m.fileref==0xFFFF)
  194.           return 0;
  195.         if (mdbGetModuleType(m.fileref)!=mtINP)
  196.         {
  197.           moduleinfostruct mi;
  198.           mdbGetModuleInfo(mi, m.fileref);
  199.           mi.flags1|=MDB_VIRTUAL;
  200.           mi.channels=1;
  201.           strcpy(mi.modname, dev->dev.dev->name);
  202.           mi.modtype=mtINP;
  203.           mdbWriteModuleInfo(m.fileref, mi);
  204.         }
  205.         if (!mdbAppend(ml, m))
  206.           return 0;
  207.       }
  208.     }
  209.  
  210.     fsConvFileName12(m.name, "DEFAULT", ".LIN");
  211.     if (fsMatchFileName12(m.name, mask))
  212.     {
  213.       m.dirref=dirref;
  214.       m.fileref=mdbGetModuleReference(m.name, 0);
  215.       if (m.fileref==0xFFFF)
  216.         return 0;
  217.       if (mdbGetModuleType(m.fileref)!=mtINP)
  218.       {
  219.         moduleinfostruct mi;
  220.         mdbGetModuleInfo(mi, m.fileref);
  221.         mi.flags1|=MDB_VIRTUAL;
  222.         mi.channels=2;
  223.         strcpy(mi.modname, "Default Line-In");
  224.         mi.modtype=mtINP;
  225.         mdbWriteModuleInfo(m.fileref, mi);
  226.       }
  227.       if (!mdbAppend(ml, m))
  228.         return 0;
  229.     }
  230.     fsConvFileName12(m.name, "DEFAULT", ".MIC");
  231.     if (fsMatchFileName12(m.name, mask))
  232.     {
  233.       m.dirref=dirref;
  234.       m.fileref=mdbGetModuleReference(m.name, 0);
  235.       if (m.fileref==0xFFFF)
  236.         return 0;
  237.       if (mdbGetModuleType(m.fileref)!=mtINP)
  238.       {
  239.         moduleinfostruct mi;
  240.         mdbGetModuleInfo(mi, m.fileref);
  241.         mi.flags1|=MDB_VIRTUAL;
  242.         mi.channels=1;
  243.         strcpy(mi.modname, "Default Microphone");
  244.         mi.modtype=mtINP;
  245.         mdbWriteModuleInfo(m.fileref, mi);
  246.       }
  247.       if (!mdbAppend(ml, m))
  248.         return 0;
  249.     }
  250.   }
  251.  
  252.   return 1;
  253. }
  254.  
  255. extern "C"
  256. {
  257.   mdbreaddirregstruct inpReadDirReg = {inpReadDir};
  258.   cpifaceplayerstruct inpPlayer = {inpOpenFile, cdaCloseFile};
  259. };
  260.